<?php
namespace app\home\controller; 
use think\Controller;
class Test extends Controller {
	public function index(){

		$ip = $this->GetIP();
		$ip2 = $this->GetIP2();
		echo $ip;
		echo $ip2;
		
	}
	public function getIP(){            
	    if (getenv("HTTP_CLIENT_IP"))
	         $ip = getenv("HTTP_CLIENT_IP");
	    else if(getenv("HTTP_X_FORWARDED_FOR"))
	            $ip = getenv("HTTP_X_FORWARDED_FOR");
	    else if(getenv("REMOTE_ADDR"))
	         $ip = getenv("REMOTE_ADDR");
	    else $ip = "Unknow";
	    
	    if(preg_match('/^((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1 -9]?\d))))$/', $ip))          
	        return $ip;
	    else
	        return '';
	}
	public function getIP2() {
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
}
elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
}
elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');

}
elseif (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
}
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
} 
	

}
